﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Global" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	EditNews
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
    <style type="text/css" media="screen">
			.error { font-weight: Bold; color: Red; }
	</style>
    <script type="text/javascript" src="/../Content/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="/../Scripts/ProductCreate.js"></script>
    <script type="text/javascript" src="/../Scripts/Global.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {

            if ($("#rbtRealEstate:checked").length == 1)
                PostRealEstate();
            else
                PostProduct();
            $("#ex-file2, #ex-file3, #ex-file4, #ex-file5").hide();

            //Chọn phần đăng sản phẩm
            $('#rbtProduct').click(function () {
                PostProduct();
            });

            //Chọn phần đăng nhà đất
            $('#rbtRealEstate').change(function () {
                PostRealEstate();
                //SelectRealEstate();
            });

            //Load danh mục con
            $("#ddlCateLevel1").change(function () {
                $.ajax({
                    type: "POST",
                    url: "/Utility/SelectChildLevel2Category",
                    data: "cateID=" + $(this).val(),
                    success: function (result) {
                        if (result.success) {
                            $("#ddlCateLevel2").empty();
                            $.each(result.data, function (index, optionData) {
                                $("#ddlCateLevel2").append("<option value='" + optionData.Value + "'>" + optionData.Text + "</option>");
                            });
                        }
                    },
                    error: function (req, status, error) {
                        alert("Sorry! We could not receive your feedback at this time.");
                    }
                });
            });

            //=====================================================================
            ////LOAD POPUP FORM ĐỂ CHỈNH SỬA HÌNH CHO SẢN PHẨM
            $(".btn_Load_PopupForm")
            .click(function () {
                $("#dialog-form").dialog("open");
                //Truyền tham số vào trong biến hidden để submit lên form và xử lý
                $("#thumbId").val($("#proThumbId").val());
                $("#oldImageName").val($("#proThumbName").val());
            });

            function updateTips(t) {
                tips
				.text(t)
				.addClass("ui-state-highlight");
                setTimeout(function () {
                    tips.removeClass("ui-state-highlight", 1500);
                }, 500);
            }

            $("#dialog-form").dialog({
                autoOpen: false,
                height: 230,
                width: 450,
                top: 100,
                modal: true,
                buttons: {
                    "Thêm album": function () {
                        var bValid = true;
                        if ($("#AblumName").val() == "" || $("#AlbumThumbnail").val() == "") {
                            $("#errors").html("Vui lòng điền đầy đủ thông tin !.");
                            updateTips("Vui lòng điền đầy đủ thông tin !.");
                            bValid = false;
                        }
                        else {
                            bValid = true;
                            $("#errors").html("");
                        }
                        if (bValid) {
                            SubmitData_Ajax("frm_AddAlbum", "")
                            $(this).dialog("close");
                        }
                    },
                    "Hủy": function () {
                        $(this).dialog("close");
                    }
                },
                close: function () {
                    $("#errors").html("");
                }
            });
            //=====================================================================

        });    //Kết thúc '$(document).ready(function ()'

        window.onload = function () {
            CKEDITOR.replace('txtDetailContent',
            {
                filebrowserImageBrowseUrl: '/Upload/Index',
                height: 400,
                ignoreEmptyParagraph: true,
                //                htmlEncodeOutput: true,
                language: 'en'
            });

            //Load danh mục dùng để edit sản phẩm
            loadCategoryToEdit('<%=ViewData["CateLevel1"] %>', '<%=ViewData["CateLevel2"] %>');
        };

    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
   <% NewsProduct newsProduct = (NewsProduct)ViewData["ProductToEdit"] ; %>
    
    <!-- ======================== FORM DÙNG ĐỂ CHỈNH SỬA HÌNH ẢNH PRODUCT ========================== -->
    <div id="dialog-form" title="Thêm Album mới" style="margin-top:10px !important">
	    <form action="<%=Url.Action("ChangeImage","Product") %>" id="frm_AddAlbum" method="post" enctype="multipart/form-data">
		    <table style="margin-top : 10px" cellspacing = "100px">
                <tr>
                    <td>
                        <div id="errors" style="color:red; font-weight:bold">&nbsp;</div>
                        <input type="hidden" name="thumbId" id="thumbId" value="" />
                        <input type="hidden" name="prodId" id="prodId" value="<%= newsProduct.NProId %>" />
                        <input type="hidden" name="oldImageName" id="oldImageName" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="AblumName">Upload hình mới </label><br />
		                <input type="file" name="AlbumThumbnail" id="AlbumThumbnail" size="50" class="text ui-widget-content ui-corner-all" />
                    </td>
                </tr>
            </table>
	    </form>
    </div>
    <!-- ==============KẾT THÚC FORM POPUP CHỈNH SỬA HÌNH  ======================-->

    <div class="private_share_post_top">
        <div class="private_sharepost_menu">
            <ul>
                <li><a href="<%= Url.Action("Index","Product", new { uid = Session["MemId"]} ) %>" id="childmenu_posting">Đăng sản phẩm</a></li>
                <li><a href="<%= Url.Action("ListToModify","Product", new { uid = Session["MemId"], p = 1} ) %>" id="childmenu_editing">Chỉnh sửa sản phẩm</a></li>
            </ul>
        </div>
    </div>
    <div class="private_content_onecol">
    <%=Html.ValidationSummary("Vui lòng nhập đầy đủ thông tin.", new { @class= "error"})%>
    <form action="<%= Url.Action("EditProduct","Product") %>" method="post" enctype="multipart/form-data">
        <table width="100%" border="0">
            <tr>
                <td align="right"><span class="private_text_title">Chọn loại tin:</span>&nbsp;</td>
                <td align="left">
                    <!-- Dùng để lưu Id của product -->
                    <input type="hidden" id="productId" name="productId" value="<%= Request["productId"] %>"/>
                    <%--<input type="radio" class="input_checkbox" id="rbtRealEstate" name="NewsType" checked="checked" value="RealEstate">--%>
                    <%= Html.RadioButton("NewsType", "RealEstate", ViewData["NewsType"] == null ? true : (ViewData["NewsType"].ToString() == "RealEstate"), new { id = "rbtRealEstate"})%>
                    <label class="private_text_title" for="rbtRealEstate">Đăng tin mục nhà đất</label>
                    <%--<input type="radio" class="input_checkbox" id="rbtProduct" name="NewsType" value="Product">--%>
                    <%= Html.RadioButton("NewsType", "Product", ViewData["NewsType"] == null ? false : (ViewData["NewsType"].ToString() == "Product"), new { id = "rbtProduct"})%>
                    <label class="private_text_title" for="rbtProduct">Đăng tin mục sản phẩm</label>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <%= Html.DropDownList("ddlCateLevel1", (SelectList)ViewData["Categories"],"Danh mục chính", new { style = "width:255px" })%>
                    <select style="width:260px" id="ddlCateLevel2" name="ddlCateLevel2">
                        <option value="0">Danh mục con</option>
                    </select>
                    <%--<select style="width:185px" id="ddlProvince" name="ddlProvince">
                        <%
                            if (ViewData["Provinces"] != null)
                            {
                                foreach (var province in (List<Province>)ViewData["Provinces"])
                                {
                                    if(newsProduct.Province.ProvId == province.ProvId)
                                        Response.Write("<option value='" + province.ProvId + "' selected='selected'>" + province.ProvName + "</option>");
                                }
                            }
                            else
                                Response.Write("<option value=-1>Không load được dữ liệu</option>");
                        %>
                    </select>--%>
                    <%= Html.DropDownList("ddlProvince", (SelectList)ViewData["Provinces"], "Danh mục tỉnh", new { style = "width:185px" })%>
                </td>
            </tr>
            <tr>
                <td width="12%" align="right" valign="middle" class="private_font_bold">
                    Tiêu đề
                </td>
                <td width="88%">
                    <%--<input type="text" name="txtTitle" id="txtTitle" class="input_full" />--%>
                    <%= Html.TextBox("txtTitle", (newsProduct == null ? "" : newsProduct.NProTitle), new { @class = "input_full" })%>
                </td>
            </tr>
            <tr>
                <td align="right" valign="middle" class="private_font_bold">
                    Xuất xứ
                </td>
                <td>
                    <%--<input type="text" name="txtFrom" id="txtFrom" class="input_full" />--%>
                    <%= Html.TextBox("txtFrom", (newsProduct == null ? "" : newsProduct.NProFrom), new { @class = "input_full" })%>
                </td>
            </tr>
            <tr>
                <td align="right" valign="middle" class="private_font_bold">
                    Giá bán
                </td>
                <td>
                    <%--<input type="text" name="txtPrice" id="txtPrice" class="input_part" />--%>
                    <%= Html.TextBox("txtPrice", (newsProduct == null ? 0 : newsProduct.NProPrice))%>
                    <select name="cbbCurrency" id="cbbCurrency" class="input_part">
                        <option value='VND'>VND</option>
                        <option value='USD'>USD</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td valign="middle" align="right" class="private_font_bold">Nhu cầu</td>
                <td align="left">
                    <%= Html.RadioButton("grpDemand","SE", newsProduct == null ? true : (newsProduct.NProNeedType.Equals("SE")), new { id = "rbtSell"})%>
                    <label for="rbtSell">Cần bán</label>
                    <%= Html.RadioButton("grpDemand", "BU", newsProduct == null ? false : (newsProduct.NProNeedType.Equals("BU")), new { id = "rbtBuy" })%>
                    <label for="rbtBuy">Cần mua</label>
                    <%= Html.RadioButton("grpDemand", "RN", newsProduct == null ? false : (newsProduct.NProNeedType.Equals("RN")), new { id = "rbtRentNeed" })%>
                    <label for="rbtRentNeed" id="lblRentNeed">Cần thuê</label>
                    <%= Html.RadioButton("grpDemand", "FR", newsProduct == null ? false : (newsProduct.NProNeedType.Equals("FR")), new { id = "rbtForRent" })%>
                    <label for="rbtForRent" id="lblForRent">Cho thuê</label>
                    <%= Html.RadioButton("grpDemand", "NP", newsProduct == null ? false : (newsProduct.NProNeedType.Equals("NP")), new { id = "rbtNewProject" })%>
                    <label for="rbtNewProject" id="lblNewProject">Dự án mới</label>
                </td>
            </tr>
            <%--<tr id="ex-file1">
                <td align="right" valign="middle" class="private_font_bold">
                    Hình mình họa
                </td>
                <td>
                    <input type="file" name="ex-file1"  />
                    <a href="#" id="ex-upload">Up thêm hình</a>
                </td>
            </tr>--%>
            <% 
                foreach (var thumb in newsProduct.NewsProductThumbs)
                {
                    if ((bool)thumb.NProThumbIsMain)
                    {
                        Response.Write("<tr>");
                        Response.Write("<td align='right' valign='middle' class='private_font_bold'>Hình chính</td>");
                        Response.Write("<td><img src='/Content/Images/Upload/" + thumb.NProThumbName + "' width='140px' height='100px'/>&nbsp;&nbsp;&nbsp;&nbsp;");
                        Response.Write("<a href='javascript:void(0)' class='btn_Load_PopupForm'>Thay đổi</a></td>");
                        Response.Write("</tr>");
                        //====================================
                        Response.Write("<input type='hidden' name='proThumbId' id='proThumbId' value='" + thumb.NProThumbId + "' />");
                        Response.Write("<input type='hidden' name='proThumbName' id='proThumbName' value='" + thumb.NProThumbName + "' />");
                    }
                    else
                    {
                        Response.Write("<tr>");
                        Response.Write("<td align='right' valign='middle' class='private_font_bold'>Hình phụ</td>");
                        Response.Write("<td><img src='/Content/Images/Upload/" + thumb.NProThumbName + "' width='140px' height='100px'/>&nbsp;&nbsp;&nbsp;&nbsp;");
                        Response.Write("<a href='javascript:void(0)' class='btn_Load_PopupForm'>Thay đổi</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                        Response.Write("<a href='" + Url.Action("DeleteImage","Product",new {id = thumb.NProThumbId, productId = thumb.NProId}) + "'>Xóa</a></td>");
                        Response.Write("</tr>");
                        //====================================
                        Response.Write("<input type='hidden' name='proThumbId' id='proThumbId' value='" + thumb.NProThumbId + "' />");
                        Response.Write("<input type='hidden' name='proThumbName' id='proThumbName' value='" + thumb.NProThumbName + "' />");
                    }
                } 
            %>
            <tr>
                <td align="right" valign="top" class="private_font_bold">
                    Mô tả chung
                </td>
                <td>
                    <%--<textarea name="txtIntro" id="txtIntro" cols="45" rows="5" class="input_full"></textarea>--%>
                    <%= Html.TextArea("txtIntro", (newsProduct == null ? "" : (newsProduct.NProIntro)), new { @class = "input_full" })%>
                </td>
            </tr>
            <tr>
                <td valign="top" align="right" class="private_font_bold">Mô tả chi tiết</td>
                <%--<td><textarea id="txtDetailContent" name="txtDetailContent" cols="30" rows="10"></textarea></td>--%>
                <td><%= Html.TextArea("txtDetailContent", (newsProduct == null ? "" : (newsProduct.NProContent)))%></td>
            </tr>
            <tr id="AttributeRealEstate">
                <td colspan='2'>
                    <table width="100%" border="0" class="private_share_post">
                        <tr>
                            <td colspan="3" bgcolor="#ebf3fb"><span class="private_text_title">Tiện ích</span></td>
                        </tr>
                        <tr>
                            <td bgcolor="#f7fbfb">
                                <input type="checkbox" name="ckbWaterSystem" id="ckbWaterSystem" />
                                <label for="ckbWaterSystem">Nước máy</label>
                            </td>
                            <td bgcolor="#f7fbfb">
                                Diện tích sử dụng: 
                                <input type="text" value="" id="txtUsableArea" name="txtUsableArea" size="5"/> mét vuông
                            </td>
                            <td bgcolor="#f7fbfb">
                                Diện tích khuôn viên: 
                                <input type="text" value="" id="txtTotalArea" name="txtTotalArea" size="5"/> mét vuông
                            </td>
                        </tr>
                        <tr>
                            <td bgcolor="#f7fbfb">
                                <input type="checkbox" name="ckbPrivateElecClock" id="ckbPrivateElecClock" />
                                <label for="ckbPrivateElecClock">Đồng hồ điện riêng</label>
                            </td>
                            <td bgcolor="#f7fbfb">
                                Số lầu:  
                                <input type="text" value="" id="txtFloorCount" name="txtFloorCount" size="2"/> 
                            </td>
                            <td bgcolor="#f7fbfb">&nbsp;</td>
                        </tr>
                        <tr>
                            <td colspan="3" bgcolor="#ebf3fb"><span class="private_text_title">Nội thất - Tiện nghi</span></td>
                        </tr>
                        <tr bgcolor="#F7FBFB">
                            <td>
                                <input type="checkbox" name="ckbElevator" id="ckbElevator" />
                                Thang máy
                                <label for="ckbElevator"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbSecurity24" id="ckbSecurity24" />
                                Bảo vệ 24/24
                                <label for="ckbSecurity24"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbCarParking" id="ckbCarParking" />
                                Chổ đậu ô tô
                                <label for="ckbCarParking"></label>
                            </td>
                        </tr>
                        <tr bgcolor="#F7FBFB">
                            <td>
                                <input type="checkbox" name="cbkGarden" id="cbkGarden" />
                                <label for="cbkGarden">Sân vườn</label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbAirCondition" id="ckbAirCondition" />
                                <label for="ckbAirCondition">Điều hòa</label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbTopFloor" id="ckbTopFloor" />
                                <label for="ckbTopFloor">Sân thượng</label>
                            </td>
                        </tr>
                        <tr bgcolor="#F7FBFB">
                            <td>
                                <input type="checkbox" name="ckbPhoneLine" id="ckbPhoneLine" />
                                Điện thoại <label for="ckbPhoneLine"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbSwimmingPool" id="ckbSwimmingPool" />
                                Hồ bơi <label for="ckbSwimmingPool"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbKitchen" id="ckbKitchen" />
                                Nhà bếp <label for="ckbKitchen"></label>
                            </td>
                        </tr>
                        <tr bgcolor="#F7FBFB">
                            <td>
                                <input type="checkbox" name="ckbGarage" id="ckbGarage" />
                                Gara ôtô<label for="ckbGarage"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbLivingRoom" id="ckbLivingRoom" />
                                Phòng khách<label for="ckbLivingRoom"></label>
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td colspan="3" bgcolor="#ebf3fb"><span class="private_text_title">Văn hóa - Xã hội</span></td>
                        </tr>
                        <tr bgcolor="#F7FBFB">
                            <td>
                                <input type="checkbox" name="ckbNearPark" id="ckbNearPark" />
                                Gần công viên<label for="ckbNearPark"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbNearEnterCenter" id="ckbNearEnterCenter" />
                                Gần trung tâm giả trí<label for="ckbNearEnterCenter"></label></td>
                            <td>
                                <input type="checkbox" name="ckbNearKinderGarden" id="ckbNearKinderGarden" />
                                Gần trường mẫu giáo<label for="ckbNearKinderGarden"></label>
                            </td>
                        </tr>
                        <tr bgcolor="#F7FBFB">
                            <td>
                                <input type="checkbox" name="ckbNearComCentral" id="ckbNearComCentral" />
                                <label for="ckbNearComCentral">Gần trung tâm thương mại</label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbNearColleage" id="ckbNearColleage" />
                                Gần trường ĐH-CĐ<label for="ckbNearColleage"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbNearHospital" id="ckbNearHospital" />
                                Gần bệnh viện<label for="ckbNearHospital"></label>
                            </td>
                        </tr>
                        <tr bgcolor="#F7FBFB">
                            <td>
                                <input type="checkbox" name="ckbNearHighSchool" id="ckbNearHighSchool" />
                                Gần trường cấp III<label for="ckbNearHighSchool"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbNearMarket" id="ckbNearMarket" />
                                Gần chợ<label for="ckbNearMarket"></label>
                            </td>
                            <td><input type="checkbox" name="ckbNearSecondarySchool" id="ckbNearSecondarySchool" />
                                Gần trường cấp II<label for="ckbNearSecondarySchool"></label>
                            </td>
                        </tr>
                        <tr bgcolor="#F7FBFB">
                            <td>
                                <input type="checkbox" name="ckbForBusiness" id="ckbForBusiness" />
                                Tiện kinh doanh<label for="ckbForBusiness"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbNearPrimarySchool" id="ckbNearPrimarySchool" />
                                Gần trường cấp I<label for="ckbNearPrimarySchool"></label>
                            </td>
                            <td>
                                <input type="checkbox" name="ckbHighIntelResident" id="ckbHighIntelResident" />
                                Khu dân trí cao<label for="ckbHighIntelResident"></label>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" bgcolor="#ebf3fb"><span class="private_text_title">Tình trạng pháp lý</span></td>
                        </tr>
                        <tr bgcolor="#F7FBFB">
                            <td><input type="radio" name="Book" id="rbtRedBook" value="RedBook" checked="checked" />
                            <label for="rbtRedBook">Sổ đỏ</label></td>
                            <td><input type="radio" name="Book" id="rbtPinkBook" value="PinkBook" />
                            <label for="rbtPinkBook">Sổ hồng</label></td>
                            <td><input type="radio" name="Book" id="rbtHandWritingBook" value="HandWritingBook" />
                            <label for="rbtHandWritingBook">Giấy tay</label></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    <input type="checkbox" name="checkbox7" id="checkbox7" /><span class="private_text_ck">Tôi
                        cam kết nội dung đăng tin hoàn toàn lành mạnh đúng với <a href="#">qui định điều khoản</a>
                        của website hoichomuaban.com.</span>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td align="center">
                    <input type="submit" id="" value="Đăng tin" class="private_bt_submit_news" />
                </td>
            </tr>
        </table>
    </form>
    </div>
</asp:Content>
